package days48;

import java.util.Scanner;

public class day25 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String line=scanner.nextLine();
            while (line.length()>1){
                int sum=0;
                for (int i = 0; i < line.length(); i++) {
                    sum+=line.charAt(i)-'0';
                }
                line=String.valueOf(sum);
            }

            System.out.println(line);
        }
    }
//    public int maximumBags(int[] capacity, int[] rocks, int additionalRocks) {
//
//    }
}
